﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SilverlightApp
{
    public partial class StoryBoard : UserControl
    {
        public StoryBoard()
        {
            InitializeComponent();
            Button btn2 = new Button();
            btn2.Name = "btn2";
            btn2.Content = "Stop";
            btn2.SetValue(Canvas.TopProperty, 120.0);
            btn2.SetValue(Canvas.LeftProperty, 100.0);
            btn2.Click += new RoutedEventHandler(btn2_Click);
            canvas1.Children.Add(btn2);
            storyboard1.Completed += new EventHandler(storyboard1_Completed);
        }

        void btn2_Click(object sender, RoutedEventArgs e)
        {
            storyboard1.Stop();
            btn1.IsEnabled = true;
        }

        void storyboard1_Completed(object sender, EventArgs e)
        {
            btn1.IsEnabled = true;
        }

        private void btn1_Click(object sender, RoutedEventArgs e)
        {
            btn1.IsEnabled = false;
            storyboard1.BeginTime = new TimeSpan(0,0,1);
            storyboard1.RepeatBehavior = RepeatBehavior.Forever;
            storyboard1.Begin();
        }
    }
}
